define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order_goods/index' + location.search,
                    add_url: 'order_goods/add',
                    edit_url: 'order_goods/edit',
                    del_url: 'order_goods/del',
                    multi_url: 'order_goods/multi',
                    import_url: 'order_goods/import',
                    table: 'order_goods',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_id', title: __('Order_id')},
                        {field: 'goods_id', title: __('Goods_id')},
                        {field: 'sku_name', title: __('Sku_name')},
                        {field: 'sku_id', title: __('Sku_id')},
                        {field: 'goods_num', title: __('Goods_num')},
                        {field: 'goods_price', title: __('Goods_price'), operate:'BETWEEN'},
                        {field: 'goods_name', title: __('Goods_name')},
                        {field: 'images', title: __('Images'), events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'goods.id', title: __('Goods.id')},
                        {field: 'goods.sort', title: __('Goods.sort')},
                        {field: 'goods.shop_id', title: __('Goods.shop_id')},
                        {field: 'goods.name', title: __('Goods.name')},
                        {field: 'goods.keyword', title: __('Goods.keyword')},
                        {field: 'goods.thumbnailimage', title: __('Goods.thumbnailimage'), events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'goods.thumbnailimages', title: __('Goods.thumbnailimages'), events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'goods.goods_attr', title: __('Goods.goods_attr')},
                        {field: 'goods.cid1', title: __('Goods.cid1')},
                        {field: 'goods.cid2', title: __('Goods.cid2')},
                        {field: 'goods.category_id', title: __('Goods.category_id')},
                        {field: 'goods.sell_real', title: __('Goods.sell_real')},
                        {field: 'goods.sell_virtual', title: __('Goods.sell_virtual')},
                        {field: 'goods.sell_num', title: __('Goods.sell_num')},
                        {field: 'goods.collect_real', title: __('Goods.collect_real')},
                        {field: 'goods.collect_virtual', title: __('Goods.collect_virtual')},
                        {field: 'goods.collect_num', title: __('Goods.collect_num')},
                        {field: 'goods.paramsjson', title: __('Goods.paramsjson')},
                        {field: 'goods.is_ship', title: __('Goods.is_ship')},
                        {field: 'goods.freight_type', title: __('Goods.freight_type')},
                        {field: 'goods.freight_id', title: __('Goods.freight_id')},
                        {field: 'goods.is_recommond', title: __('Goods.is_recommond')},
                        {field: 'goods.status', title: __('Goods.status'), formatter: Table.api.formatter.status},
                        {field: 'goods.state', title: __('Goods.state')},
                        {field: 'goods.is_good', title: __('Goods.is_good')},
                        {field: 'goods.is_checking', title: __('Goods.is_checking')},
                        {field: 'goods.note', title: __('Goods.note')},
                        {field: 'goods.max_price', title: __('Goods.max_price'), operate:'BETWEEN'},
                        {field: 'goods.min_price', title: __('Goods.min_price'), operate:'BETWEEN'},
                        {field: 'goods.createtime', title: __('Goods.createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'goods.updatetime', title: __('Goods.updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'goods.deletetime', title: __('Goods.deletetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'goods.checktime', title: __('Goods.checktime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});